package com.example.demo1.controller;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.example.demo1.entity.Member;
import com.example.demo1.service.IMember;

@RestController
@MapperScan("com.example.demo1.dao") //mapper扫描
public class LoginController{

    @GetMapping(value = "/hello")
    public String hello(){
        System.out.println("Hello");
        return "Log";
    }

    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public String login(){
        System.out.println("Hello login");
        return "Log";
    }
    
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String doLogin(String name,String password) {
        System.out.println("loginName is:"+name);
        System.out.println("loginPassword is:"+password);
        try {
            Member member = iMemberFunc.login(name, password);
            if(member == null){
                System.out.println("登录失败");
                return "Log_fail";
            }else {
                System.out.println("登录成功");
                return "Log_success";
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println(e.getMessage());
            System.out.println("登录异常");
        }
        return null;

    }

}